package com.linsir.ext.beetl;

import org.beetl.core.Context;
import org.beetl.core.Function;

import com.linsir.common.utils.xx;
/**
 * @author linsir
 * @title: JsFormatFun
 * @projectName linsir-mu
 * @description: JS 参数自动获取并处理默认值
 * @date 2021/12/3 22:55
 */
public class JsFormatFun implements Function{

    @Override
    public Object call(Object[] paras, Context ctx) {
        if (paras.length != 1) {
            throw new RuntimeException("参数错误，期望Object");
        }
        Object obj = paras[0];
        if (xx.isEmpty(obj)) {
            return "undefined";
        }
        if (xx.isNum(obj)) {
            return obj.toString();
        }
        return xx.format(obj);
    }
}
